{% extends "base.html" %}

{% block title %}用户管理{% endblock %}

{% block content %}
<h2>用户管理</h2>
<button type="button" class="btn btn-success mb-3" onclick="window.location.href='{{ url_for('admin.add_user') }}'">新增用户</button>
<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>角色</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
            <tr>
                <td>{{ user.id }}</td>
                <td>{{ user.username }}</td>
                <td>
                    {% if user.is_admin %}
                    <span class="badge bg-primary">管理员</span>
                    {% else %}
                    <span class="badge bg-secondary">普通用户</span>
                    {% endif %}
                </td>
                <td>
                    <button type="button" class="btn btn-sm btn-outline-primary" onclick="window.location.href='{{ url_for('admin.edit_user', user_id=user.id) }}'">编辑</button>
                    <form action="{{ url_for('admin.delete_user', user_id=user.id) }}" method="post" style="display:inline;">
                        <button type="submit" class="btn btn-sm btn-outline-danger">删除</button>
                    </form>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
